#include "config.h"
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
	char see[5];
	char sqllang[255];
	MYSQL *conn;	 // the connection
	MYSQL_RES *sql_query;	// the results
	MYSQL_ROW row;	// the results row (line by line)

	ConfigFile cf("config.txt");

	MySQL_DB DBconn;
	conn = DBconn.mysql_connect_setup(
		cf.Seclect_Section("dbserver","host").c_str(), 
		cf.Seclect_Section("dbserver","user").c_str(), 
		cf.Seclect_Section("dbserver","passwd").c_str(), 
		cf.Seclect_Section("dbserver","defaultdb").c_str(), 
		atoi(cf.Seclect_Section("dbserver","port").c_str())
		);

	cout << "Input Two Word :";
	cin >> see;
	sprintf(sqllang, "select * from geo_country where country='%s'",see);
	sql_query = DBconn.mysql_perform_query(conn, sqllang);

	if(mysql_fetch_row(sql_query) == NULL){
		printf("Search Not Found Country\n");
	}
	while ((row = mysql_fetch_row(sql_query)) != NULL){
		printf("start_ip:%15s end_ip:%15s country:%2s name: %8s\n", row[0], row[1], row[4], row[5]);
	}
	/* clean up the database result set */
	mysql_free_result(sql_query);
	/* clean up the database link */
	mysql_close(conn);

	system("pause");
	return 0;
}